I have made an Asp.Net webforms website in C# using the .net framework 4.6.1.
The website works perfectly but when I try to optimize the CSS load using the weboptimization component I get a 404 from the css url request.
Please note that I have also the js bundle that works perfectly.
in the .aspx page I have in the head:
<webopt:BundleReference runat="server" Path="~/stylesheets" />
the bundle.config is in the root of the site structure and its content is:
<?xml version="1.0" encoding="utf-8" ?>
<bundles version="1.2">
<styleBundle path="~/stylesheets">
<include path="~/Bootstrap/css/bootstrap.css" />
<include path="~/css/style.css" />
<include path="~/css/custom.css" />
</styleBundle>
</bundles>
Inspecting the network request I see that the request for stylesheets
where base-site is instead the js bundle
Global.asax file:
void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleTable.EnableOptimizations = true;
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
web.config:
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.6.1">
...
<httpRuntime targetFramework="4.6.1"/>
<pages enableEventValidation="true">
<namespaces>
<add namespace="System.Web.Optimization"/>
<add namespace="Microsoft.AspNet.Identity"/>
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
...
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication"/>
<remove name="BundleModule"/>
<add name="BundleModule" type="System.Web.Optimization.BundleModule"/>
</modules>
...
</system.webServer>
I have an identical website with the same web.config, same routing configuration with EnableFriendlyUrls(True) where the CSS bundle is correctly provided.
It doesn't work both local on VS2017 and on the production server.
There is no folder or other pages named "stylesheets"
The CSS files are well-formed
I've tried also with a single CSS file, but I get always a 404.
The routing for all the other pages and JS bundle works fine
Why the CSS bundle doesn't work?
Is there something I can do to understand where is the issue?
After several tests, I have found that every time I make a change in the css bundle.config file I have to close and restart Visual Studio.
Restarting IIS Express is not enough.
On the production server, I have to stop and start again the website, recycling the application pool.
Related
I have developed a web application using c# and asp.net but when I am trying to publish and put it into the server using ftp then I am getting this following error:
Configuration Error
Description: An error occurred during the processing of a configuration
file required to service this request. Please review the specific error
details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level. This error
can be caused by a virtual directory not being configured as an application
in IIS.
Source File: \\fs8-n02\stor10wc2dfw1\555713\570520\www.gxxxxjjsxx.ssd\web\content\2way\armb
\web.config Line: 9
Here if I check on my Line 9 of the web config file then I get this:
<authentication mode="Forms">
And here is my complete web config file code:
<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<authentication mode="Forms">
<forms loginUrl="Login.aspx" timeout="2880"/>
</authentication>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<pages validateRequest="false">
<controls>
<add tagPrefix="ajaxtoolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolKit" />
</controls>
</pages>
<globalization culture="en-GB"/>
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
I have checked whether I have multiple web config files but I could not find something like that. And also I have used this published folder into my IIS and I can browse the site from my localhost using IIS but still when ever I am trying to browse using the link:
I am getting the same error. Please help me on this. Thanks.
Here is my solution to the problem: Actually the path was not configured properly into the IIS as a virtual directory. So, that I had to create a proper virtual directory and then only I am able to access the site.
Its working absolutely fine on my local machine.
I designed the application on 4.0 framework, and changed the target framework to 4.5 when I deployed the code.
Web Config File
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpHandlers>
<add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</httpHandlers>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" preCondition="integratedMode"/>
</handlers>
</system.webServer>
.aspx Code for control
<cc1:AjaxFileUpload ID="AjaxFileUpload1" throbberid="myThrobber" OnClientUploadComplete="uploadComplete" onuploadcomplete="AjaxFileUpload1_UploadComplete"
runat="server" MaximumNumberOfFiles="4"></cc1:AjaxFileUpload>
Status bar shows image uploaded 100% but after that it shows error in red.
Thanks in Advance :)
I did some more R and D on control processing and came to know that Ajaxfileupload control, temporarily saves the file in windows temp directory and when it process save command, it then delete the file in temp and move it to your location.
Since i am uaing shared platform i dont have full permission to it.
I replaced all ajaxfileupload to asyncfileupload, now it works fine.
Please am fairly new to programming in asp.net and now am following the steps in a textbook to design an e-commerce web application.
I am using UrlRewritingNet dll from http://www.urlrewriting.net/ to create search engine friendly urls on the application. I unzipped the urlrewritingnet zip and copied its dll file to my application's bin folder. I also copied its urlrewritingnet.xsd file to my project folder. The textbook am working from uses the dll from urlrewriter.net with different configurations which I tried in my project but it didn't work. The textbook also uses visual web developer 2005. Am programming in visual studio 2012 (C#). For now am trying to rewrite the url of my catalogs page so as to test if the configuration in my web.config file is correct. I'm doing the configuration in my web.config, not in IIS. I do not want any IIS configurations because am imagining a scenario where I don't have access to the server.
I keep getting an internal server error that displays like this:
HTTP Error 500.22 - Internal Server Error
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
this is the url which I want to rewrite: http://localhost:1036/Catalog.aspx?DepartmentID=1
This is my config file:
<configuration>
<configSections>
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission ="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>
<urlrewritingnet
rewriteOnlyVirtualUrls="true"
contextItemsPrefix="QueryString"
defaultProvider = "RegEx"
defaultPage = "Default.aspx"
xmlns="http://www.urlrewriting.net/schemas/config/2006/07" >
<rewrites>
<add name="Rule1"
provider="RegEx"
virtualUrl="^.*-d([0-9]+)/?$"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/Catalog.aspx?DepartmentID=$1"
ignoreCase="true" />
</rewrites>
</urlrewritingnet>
<appSettings>
<add key="MailServer" value="smtp.gmail.com"/>
<add key="MailUsername" value="engr.ejikeeze#gmail.com"/>
<add key="MailPassword" value="keeplooking"/>
<add key="MailFrom" value="engr.ejikeeze#gmail.com"/>
<add key="EnableErrorLogEmail" value="false"/>
<add key="ErrorLogEmail" value="engr.ejikeeze#gmail.com"/>
<add key="ProductsPerPage" value="6"/>
<add key="ProductDescriptionLength" value="60"/>
<add key="SiteName" value="BalloonShop"/>
</appSettings>
<connectionStrings>
<add name="BalloonShopConnection" connectionString="server = (local)\SQLEXPRESS; Database = BalloonShop; User = balloonshop; password=ecommerce" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<httpModules>
<add name="UrlRewriteModule"
type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US"/>
<customErrors mode="RemoteOnly" defaultRedirect="Oops.aspx" />
<pages theme="BalloonShopDefault">
<controls>
<add src="~/UserControls/DepartmentsList.ascx" tagName="DepartmentsList" tagPrefix="BSUC"/>
</controls>
</pages>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Pls I need you lovely guys to help me out. Am really stuck. I've searched all round the internet for over 4 days in search of solution but to no avail. Thanks in anticipation.
You can checkout the following link:url-rewriting-in-Asp-Net
I am getting a 401.2 error on the default document in VS2013 (and IIS). Here are the steps I'm taking:
In VS2013, right click choose "New Project"
Choose "ASP.NET Web Application", click OK
Choose "Empty" project, Check "Web Forms" at the bottom and click OK
Right click on the project and choose "Add | Web Form" - named
Default.aspx with "Authentication Succeeded" as the page content
Right click on the project and choose "Add | Web Form" - named
Login.aspx
Add a "Login" as the page content
Assign an "Authentication" event handler that sets "e.Authenticated
= true"
Update the web.config as listed below
Press F5
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="Login.aspx" />
</authentication>
</system.web>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
</files>
</defaultDocument>
<security>
<authorization>
<remove users="*"/>
<add accessType="Deny" users="?" />
<add accessType="Allow" users="*"/>
</authorization>
</security>
</system.webServer>
</configuration>
The behavior that I'm seeing is that http://localhost:12345/Default.aspx behaves correctly (always). In other words, when I first go to Default.aspx, it redirects me to the Login.aspx page. Once I've authenticated, I can see the Default.aspx page. If I logout and try to go to the Default.aspx page again it redirects me to login first.
However, when I got the / URL instead (no Default.aspx) I get a 401.2 error (even if I've authenticated 1st)?
The Default.aspx page is listed as a default document, and if I remove the "Deny" line from the Web.Config - then the default document behaves as expected. But when Deny ? is listed in the web config, suddenly the default document stops working and I have to go to /Default.aspx in order to avoid a 401.2 error.
Any suggests as to why this would behave like this?
I see no errors about any of this in the event log. I see the same behavior when using IISExpress (in VS by pressing F5) or with IIS when going to the public URL directly through a browser.
I hesitate to offer this as an answer as I don't understand exactly why it worked for me. However it is too long for a comment and it might help you.
I found that adding the following to the System.Webserver section solved this problem:
<modules>
<remove name="FormsAuthentication"/>
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
</modules>
The key seems to be to remove the managedHandler Precondition from the FormsAuthentication module. As I understand it this is only supposed to optimize serving of static content. So I do not at this point know why it would have this effect. I stumbled on this trying to establish if FormsAuthentication module needed to be registered in the System.Webserver section.
I am using VS 2008 and C# but when I added namespace in web.config file, that namespace is not imported or included in code behind or aspx
I have also read this question but not get the required answer.
web.config code
<configuration>
<system.web>
<pages>
<namespaces>
<add namespace="System.Data" />
<add namespace="System.Text"/>
</namespaces>
</pages>
</system.web>
</configuration>
You need to put them in the correct <system.web> section. e.g.:
<configuration>
<system.web>
<pages>
<namespaces>
<add namespace="System.Data" />
<add namespace="System.Text"/>
</namespaces>
</pages>
</system.web>
</configuration>
and put them in the correct web.config
i.e. the second web.config file is the Views folder and is specific to views. These settings do not go in the root web.config.
The purpose of these settings is to make the libraries available to the ASPX pages (e.g. for Intellisense) and it is not used for the code-behind. You still need to have using statements in your actual code as that is just plain c# programming.
The purpose of the namespace section is to get around having to do the import in the .aspx page. Code behind in C# still requires you to have the using statements at the top of your .cs file.
There is no way to get around this.