What is the effect of omitting "webpages:Enabled" in web.config? - asp.net-mvc

I've seen the question "what is the function of webpages:Enabled in MVC 3 web.config" but the answer merely explains that setting it to "false" disables use of CSHTML pages (although the is no link to the documentation).
I have a project which fails to build unless the line <add key="webpages:Enabled" value="true"> is removed from the web.config file.
Can someone (provide a link to) tell me what the effect of omitting it is? Is the default to allow or deny CSHTML pages?
Thanks

Default value is null which is interpreted as 'true' that would enable *.cshtml pages to be accessible directly.
You may refer to the code base here for reference:
https://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.WebPages.Deployment/WebPagesDeployment.cs

Related

How to disable language embedding in URLs in Sitecore?

After setting up a simple Sitecore site, links to pages sometimes contain the current language:
http://example.com/item.aspx
http://example.com/en/item.aspx
I would like to disable this behavior so that all links point to http://example.com/item.aspx without the language as part of the path. How can this be done?
The web.config has a configuration setting for <linkManager> where the languageEmbedding option can be configured:
<linkManager defaultProvider="sitecore">
<providers>
<clear/>
<add name="sitecore" ... languageEmbedding="asNeeded" ... />
</providers>
</linkManager>
The languageEmbedding options are:
asNeeded
always
never
Changing the config to use languageEmbedding="never" will stop the language from showing up in the URL, and likewise languageEmbedding="always" will force the language to always show up in the URL.
You should not use the "asNeeded" option as it might cause multiple urls for the same pages. Use either "never" or "always" which is much more SEO-friendly

How to force a specific uiculture using web.config in MVC

I have added Resource.fr-FR.resx to my project and have done the globalization setting in
web.config as follows.
<system.web>
<globalization culture="fr-FR" uiCulture="fr"/>
</system.web>
that is all you need according to http://msdn.microsoft.com/en-us/library/bz9tc508%28v=vs.80%29.aspx
but when I run my app it is still in english
I have checked "Thread.CurrentThread.CurrentUICulture" in Application_Start() and it says FR.
what am I missing?
the same thing has been posted in
MVC 3 Setting uiCulture does not work
but no answers.
Culture is not the same thing as Language. A "culture" is a set of formatting rules for dates/times, currency, calendaring, and a few other things (like text Title Casing rules).
Setting a culture will not automatically localize your application (where localization is when all of the human-readable strings are translated into another language, such as French). Localization and UI translation is a long, painful and expensive process. ASP.NET does not do it for you.
If you want to localize your application, you need to ensure that all human-readable strings are stored in a resource file (.resx in .NET) and you have created "satellite assemblies" that contain translated strings for other languages. You then need to ensure that ever string displayed to the user in your application uses the Resources APIs (or IDE-generated helper classes). This is painful because it means going from this in your *.aspx files...
<p>Hello, welcome. This is in English.</p>
...to this:
<p><%= Resources.WelcomeMessage %></p>
...or this (if you have too many strings to be managed by the Resources helper class):
<p><%= ResourceManager.GetString("HomePage_WelcomeMessage") %></p>
...doing this, of course, breaks any visual-designers for your website, for example.

IIS hosting ASP.NET MVC site gives http 404 for urls containing 'web.config'

Requesting a page from IIS (hosts ASP.NET MVC 3 site) with url containing web.config gives 404 error. Urls with app.config have no problem. Local Visual Studio development server has no issues with this type of urls.
1 - What are any other special words other than web.config, being handled this way by IIS?
In request filtering page/hidden segments tab this is the current state:
I guess these are not special words, because IIS handles words like bin, App_code etc without a problem.
Answer: I guess these are the words being handled by IIS this way. So these are the default words I think and this list is configurable (new items can be added to this list).
2 - Are there any quick fixes (like by web.config modification) to handle urls with these special words?
Btw, I am not trying to serve the web.config file. Url format is : www.mysite.com/es/web.config/1
This is part of the IIS configuration under the Request Filtering section:
You can add/remove filters.
However, I do believe this is a really bad idea to remove web.config from it.
http://www.iis.net/configreference/system.webserver/security/requestfiltering
Cause:
As you already shown a snapshot of IIS configuration. These are reserved folder & files in .Net application, so IIS want to preserve those for security.
URLs which contain these strings as returned as 404 response only if these comes in before ? AND exactly between 2 slashes /../ OR at last. Eg: www.example.com/bin/anything.ext OR www.example.com/folder/sub/web.config
IIS match these string anywhere coz, web.config can we at any directory level.
If anything is with those string are there THEN page will be served by IIS. Eg: www.example.com/bin-folder/anthing.ext OR www.example.com/sub/bin.html OR www.example.com/-web.confing/page.aspx are OK.
I recommend to use some other words with these strings OR use at end of URLs with extensions, so that it will not come between two slashes.
Eg: www.example.com/en-web.config/1 OR www.example.com/en/1/web.config.aspx
Even then I have one Tricky Solution:
If you really need these strings exactly without other words in URL THEN I recommend to use URL-ReWrite.. This may not be quick at whole but except 2nd step its quick and handy, coz second step depends on your application.
1- Add this rule in IIS at top level:
regexp match: (/web|^web)\.(config$|config/) //OR as your requirement
re-write to: handler.aspx?url={REQUEST_URI}
<rule name="web-config" stopProcessing="true">
<match url="(/web|^web)\.(config$|config/)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="handler.aspx?url={REQUEST_URI}" appendQueryString="false" />
</rule>
2- In handler.aspx (or in any other language page) check the url GET variable and respond accordingly.Request.QueryString("url")
Do it carefully coz here you are controlling security.
I suggest to include the actual page content to response in handler.aspx or handler.php only rather then redirecting etc.
Before including content verify URL first(by regular expression etc.), and include content hardcoded, do not take any part of URL in to variable and use that variable in response-inclusion-code.
3- After that at last from IIS manager, In a specific website go to request filtering->hidden segment tab and delete the desire string. Eg: web.config. This step can be done by web.config also:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200" />
<hiddenSegments>
<remove segment="web.config" />
</hiddenSegments>
</requestFiltering>
</security>
Now, IIS will serve the page and your handler page will show the output with exact same URL in user browser.

Invoke ASP.NET MVC Controller When Requesting .html file

I need to add some new life to a legacy application :)
I'd like to call an MVC controller when a "static" HTML page is requested in order to add some markup to the page before returning it to the client.
I tried to follow the approach found in this thread: How to read web.config settings in .html page?
...but even though I have this route defined:
routes.MapRoute(
name: "Topic",
url: "html/{fileName}.html",
defaults: new { controller = "Topic", action = "Index" });
the controller is not being called. I have my web.config defined with:
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="HTML" path="*.html" verb="*"
type="System.Web.UI.PageHandlerFactory"
resourceType="File" preCondition="integratedMode" />
I suspect that I need to call something else besides the PageHandlerFactory or perhaps the issue is something entirely different.
UPDATE: My dev environment is working with integrated pipeline mode, but I need to check if my production environment will support it.
If you do this:
routes.RouteExistingFiles = true;
You should find this works - even without the handler addition. In the controller you can load the HTML directly using the HostingEnvironment.VirtualPathProvider's GetFile method and do something with it - or better still just use a normal MVC view that renders the same content as the static file, just with your additions.
Although be aware that this means any files that are potentially caught by any routes will be pushed into the MVC pipeline. This isn't generally a concern, however, if decent separation of routes and physical paths is used.
I setup the same situation as you and it worked well for me, so you have the key components in place. Some things to keep in mind for the testing and troubleshooting:
Your web.config does need the build provider for the html extension:
<system.web>
<compilation>
<buildProviders>
<add extension=".html"
type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
</system.web>
A copy and paste of your handlers works for me, so that looks good.
And a copy and paste of your MapRoute works for me too, although I used the default Home controller in a clean project. So as a double check just confirm that you have a controller called Topic with an ActionResult method called Index().
And make sure that your url is localhost.com:{port}/html/test.html with the /html/ in the path since your rule asks for that.
Another good test is to change your MapRoute to use aspx instead and test an aspx page and see if that works. That will confirm whether or not it's the IIS mappings or if it's the MVC rules. If it works with aspx then the issue is related to the handler, but if it fails with aspx too then it's something with MVC.
Also confirm that you're using IIS Express and not Cassini. Cassini will not handle that correctly, but IIS Express will. You can confirm by right-clicking on your project and you should see a menu option called "Use Visual Studio Development Studio...". That will only exist if you are currently using IIS Express.

Localization in ASP.NET MVC

Visual Studio 2008
I want to bring some localisation into my ASP.NET MVC site.
Someone suggested creating a resource file "Strings.resx" as a publically strongly typed resource, which works nicely and allows me to write
<title><%= Strings.MyView_Title %></title>
I then proceeded to add a file "Strings.da.resx". This file is created right next to the first one, and defaults to "Access Modifier : No Compilation", whereas the first (the one without language modifier) defaulted to "Interal".
I can see in the bin directory that a directory has been created ("da") with a resource.dll, however, I cannot see any of the translated texts on my site.
I have checked with the browser that the only preferred langauge is Danish (da-DK), but I only see the english texts.
Questions:
1) Do I need to enable something in web.config ?
2) Am i creating the right files, with the correct types (i.e. should #2 be "No compilation") ?
In your views, do you have a page directive?
If so, do you have UICulture="Auto" and Culture="Auto"?
For example...
<%# Page Language="C#" Inherits="..."
culture="auto" uiculture="auto" %>
This will ensure that the Accept-Language header, passed by the browser in the request, gets used to set the Thread cultures. It's the UICulture that influences which resource file to pick.
For more on ASP.NET i18n this book is very good...
http://www.amazon.co.uk/NET-Internationalization-Developers-Guide-Building/dp/0321341384/ref=sr_1_1?ie=UTF8&s=books&qid=1241010151&sr=8-1
It doesn't cover MVC, but covers ASP.NET and, as such, many things continue to be relevant.
First you have to create action filter that will switch culture of request thread.
OR
Set your globalization element to UICulture="Auto" and Culture="Auto"
Check this screencast, it is in Russian but code samples are understandable.

Resources