2014-09-03 10 views
6

मेरे पास एक कोणीय जेएस एप्लीकेशन है जो लिंकिंग के लिए यूआरएल रिवाइटिंग का उपयोग करता है।आईआईएस यूआरएल रिवाइट नियम

<rewrite> 
<rules> 
    <rule name="MainRule" stopProcessing="true"> 
    <match url=".*" /> 
    <conditions logicalGrouping="MatchAll"> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="^api/(.*)" negate="false" /> 
    </conditions> 
    <action type="Rewrite" url="Default.cshtml" /> 
    </rule> 
</rules> 

मैं पर एसओ इस समाधान पाया: How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode? और एक संशोधन मेरी एपीआई के माध्यम से पारित करने के लिए अनुमति देने के लिए बनाया मेरे पुनर्लेखन नियम की तरह दिखता है।

अनिवार्य रूप से, मैं अपने सभी अनुरोधों को Default.cshtml EXCEPT कॉल को अपने वेब एपीआई पर रीडायरेक्ट करना चाहता हूं। यह बहुत अच्छा काम करता है जब मैं बेस यूआरएल पर ऐप लोड करता हूं जैसे: localhost/myapp। हालांकि, अगर मैं की तरह एक कोणीय मार्ग पर पृष्ठ को रीलोड: localhost/myapp/dashboard यह कह रही है विफल रहता है:

<Error><Message>No HTTP resource was found that matches the request URI 'http://localhost/myapp/dashboard'.</Message> 
<MessageDetail>No type was found that matches the controller named 'dashboard'.</MessageDetail></Error> 

मैं चारों ओर मैं कहाँ किया था एक काम है:

<rewrite> 
    <rules> 
    <rule name="Default" stopProcessing="true"> 
     <match url="^(?!lib|api|dist|assets|app/|bower|common|main|signalr|templates|bower_components/).*" /> 
     <action type="Rewrite" url="Default.cshtml" /> 
    </rule> 
    </rules> 
</rewrite> 

और यह ठीक काम किया। कोई विचार है कि मैं उपरोक्त क्लीनर समाधान का उपयोग कैसे कर सकता हूं और फिर भी पुनः लिखना चाहता हूं?

उत्तर

6

मैं पैटर्न बदल सकते हैं और स्थानों के एक जोड़े में {REQUEST_URI} को {REQUEST_FILE} बदलने की जरूरत है। मेरी डेमो यहाँ देखें:

<rewrite> 
    <rules> 
    <rule name="MainRule" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions logicalGrouping="MatchAll"> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     <add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" /> 
     <add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="Default.cshtml" /> 
    </rule> 
    </rules> 
</rewrite> 
+0

कि signalr पैटर्न एक lifesaver था। उसके साथ कुछ घंटों के लिए संघर्ष कर रहा था। भविष्य के उपयोगकर्ताओं के लिए एक और बिंदु यह है कि अगर आप startup.cs app.start() में अपना रूट रूट निर्दिष्ट करते हैं तो आपको समस्याएं होंगी। मुझे "/ www" के रूट रूट को हटाना पड़ा और बस इसे सिग्नलआर मैपिंग में छोड़ दें। –

+0

मैं तुमसे प्यार करता हूँ दोस्त! आपका सिग्नलर पॉटर एक lifesaver² था बस इसे व्यवस्थापक (मेरे फ़ोल्डर आवेदन) में बदल दिया और एक आकर्षण की तरह काम किया। मेरे पास कोई सुराग नहीं है इसका मतलब क्या है, cuz मैं सिर्फ एक डिजाइनर lmao हूँ, लेकिन यह काम किया। इसलिए आपका धन्यवाद। –

संबंधित मुद्दे