WCF web service removing svc extension adds .svc to all extensions
I've applied an URL Rewrite rule in IIS 7 as follows:
Pattern: ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-./()]+)
RewriteUrl: {R:1}.svc/{R:2}
This works perfect when I call my service like so: http://mysite/site/myservice/input/params
The issue I am faced with is that all other links to HTML files within my project seem to have been appended with .svc, for example this code does not work:
< link rel="stylesheet" type="text/css" href="StyleSheet/StyleSheet.css" />
When I try to navigate to the URL in a web browser I receive an error message as follows:
the resource cannot be found: Requested URL: /site/stylesheet*.svc*/stylesheet.css
IIS seems to correctly remove svc when it is present, 开发者_开发百科but adds it in cases where it is not present.
Any ideas??
What you're describing is in fact the correct behavior given how the rewrite rule is defined. Remember, the rule basically says, for any incoming URL that matches the pattern ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-./()]+)
, rewrite it so that .svc
is appended to the 1st group.
Obviously, that's not what you want. Hence, you need to insure that the rewrite is only applied to some URLs, i.e. your service calls.
I'd suggest to place all your .svc
files in a dedicated subfolder, e.g. "services", and change the rule like so:
^services/([0-9a-zA-Z-]+)/([0-9a-zA-Z-./()]+)
That way, only service URLs will be rewritten, and all others won't be touched as they don't match the pattern any longer.
精彩评论