Images folder in separate applications - asp.net

I have a web application with an admin panel. The admin panel is a webform project and I also have an MVC project to list products inserted in admin panel. But when I upload images to ProductImgs folder in webform project, how can I get them from MVC project? Or can I save them to the MVC project folder?

Ok so sounds like you are trying to share images between two web applications? EDIT Also you are trying to do this using Cassini (the inbuilt dev web server).
The easiest way to do this is to move your development environment to using IIS and then create a virtual directory within your mvc project in IIS that points to the images folder in your other site (on your file system). NB Moving to IIS will also have the added benefits of making your solution be more in line with how it will be deployed which IMHO is a great benefit.
Say you call this virtual directory 'images' and it has two images (image1.jpg and image2.jpg).
You can then reference these images from your mvc site by using
<img src="/images/image1.jpg" />
Here is a link on how to create Virtual Directories.
http://support.microsoft.com/kb/172138

Now i found the solution: here is the root web.config to solve this issue
<location inheritInChildApplications="false">
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
<add namespace="EkosWeb.Helpers"/>
</namespaces>
</pages>
</system.web>
</location>
I need to add inheritInChildApplications="false" to location.

Related

same ScriptResource,axd loaded twice

Good Morning,
We have an existing application that is stable and error free on a Windows Server 2008R2 with IIS 7.5 / .NET 4.5.
We are planning a move to Windows Server 2012R2 with IIS 8.5 / .NET 4.5 and are now encountered the problem that the application (identical binaries / configuration) are indeed injected two ScriptResource.axd files, but both contain the same content (different URLs).
Because of this, the MicrosoftAjaxWebforms.js, which provides "Sys.WebForms" is missing and i'm getting the Error
Unable to get property 'PageRequestManager' of undefined or null reference
The problem is browser Independent on two independent virtual machines.
The application runs in classic mode, the web.config does not contain the < xhtmlConformance > tag.
There are all the latest server updates.
All other functionalities of the application are working properly.
I hope some of you encountered the same Problem and know the solution.
Greetings, Verni
EDITH:
Snippet of web.config (system.web section)
<system.web>
<httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="" targetFramework="4.5" enableVersionHeader="false" />
<sessionState timeout="30" mode="StateServer" stateConnectionString="tcpip=...:42424" />
<httpModules>
<add name="LinkPartnerModule" type="....LinkPartnerModule, ..." />
<add name="RedirectModule" type="....RedirectModule, ..." />
<add name="ScriptCompressorModule" type="ScriptCompressorModule, ..." />
</httpModules>
<httpHandlers>
<remove verb="*" path="scriptresource.axd"/> // added from StackOverflow
<add verb="*" path="*js.axd" type="ScriptCompressorHandler" />
</httpHandlers>
<compilation debug="false" defaultLanguage="c#" targetFramework="4.5">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Services.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<globalization culture="de-DE" enableClientBasedCulture="true" fileEncoding="utf-8" uiCulture="de" />
<pages compilationMode="Auto" styleSheetTheme="*" validateRequest="false" enableEventValidation="false" controlRenderingCompatibilityVersion="3.5" enableViewState="true" clientIDMode="AutoID">
</system.web>
<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="true" enableCaching="true" />
</scripting>
</system.web.extensions>
We had this issue as well for an application running in classic mode. The issue that time turned out to be multiple httphandlers registered for the .axd extension.
If you in your web.config make sure to remove any .axd handler before adding them it might resolve your issue.
Something like:
<remove verb="*" path="scriptresource.axd"/>
Edit:
When looking at your web.config I'm pretty sure the problem is related to the scriptcompressorhandler and module. As you stated this only happens using HTTPS and I suspect that what happens is that the module still runs over HTTPS but the handler does not. This means that the module sends the compressed version over to the regular scriptresource handler and a new copy of the script is outputted.
The solution would be to either activate scriptcompressorhandler over HTTPS as well or make sure the module is not run over HTTPS.
I fixed the Problem.
The reason was an misconfigured ARR (Application Request Router),
where SSL-Offloading was active.
The main reason of misconfiguration was the "function" that activates SSL-Offloading if no URL-Rewrite Rule is there with name like 'ARR_farmName_loadbalance_SSL'.
If this Rule will be deleted, the manager activates SSL-Offloading automatically.
Thanks to Robban, who brought me to HTTPS / SSL.

mvc 4 razor view do not understand #Html.Kendo()

I am facing one problem with Kendo UI server wrappers in ASP.NET MVC 4
If I use .ASPX default view It understands the
<%: Html.Kendo().Grid() %>
But at the same time If I try to add Razor view
It do not understand
#(Html.Kendo() ) systax.
I have entry in web.config as well
<namespaces>
<add namespace="Kendo.Mvc.UI" />
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
<handlers>
<add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
Pl tell me what I must be missing and where
Thanks and Regards,
Amit
To register Kendo UI using Razor templates make sure you have the below in your Views\Web.config.
Towards the bottom of the page also details the setup in telerik's documentation.
http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/asp-net-mvc-4
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory,
System.Web.Mvc, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
...
<add namespace="Kendo.Mvc"/>
<add namespace="Kendo.Mvc.UI"/>
</namespaces>
</pages>
</system.web.webPages.razor>
I also have the below in my main Web.config file.
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
...
<add assembly="Kendo.Mvc"/>
</assemblies>
</compilation>
</system.web>
Adding #using Kendo.Mvc.UI at the top of the page and it worked for me
Check if your web.config settings is in the View Folder ( web.config files) not the root Web.config

.net login controls uses windows authintication by default

I just developed an web app using VS 2010 framework 4 it contains login control on the default.aspx and login status in the master page everytime Irun the application It ogin using windows username and I can't even logoff any help
here is the web.config
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
<buildProviders>
<add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"/>
</buildProviders>
</compilation>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
and here is an image how it looks like
how can I prevent this behavior ?
Unless I'm misunderstanding something, authentication uses Windows Auth by default. You want to use something else. You need to change the authentication mode to forms or whatever you plan on using.
<system.web>
<!-- mode=[Windows|Forms|Passport|None] -->
<authentication mode="Forms" />
</system.web>

MVC 4 - Use Razor Views in Class Library

I am trying to have MVC 4 Razor View in a Class Library Project.
I added Web.Config files to my class library root folder and views folder but in my view #model is still not recongnized.
I also added the Microsoft.AspNet.Mvc package to the project to.
Does anyone knows how to solve this?
This is my Web.Config files:
1 - Views Folder
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
2 - Root folder
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
Does anyone knows what am I missing?
Thank You,
Miguel
It turns out the easy solution is to create it as a web application, but that might not sit well with everyone.
First Attempt
I myself also had a class library I wanted to create some controls in, and yet I wanted to have a working Razor View, with full intellisence support. The trick to that is:
Add References (for MVC)
Add ProjectTypeGuids to .csproj (edit as text) after ProjectGUID: <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
Add a .cshtml razor view file (it wont' work right until the next parts)
Add a Web.Config file (see your View folder web.config)
Change Project Properties Build output path to bin\ (not bin\Debug)
Clean and Build Solution
Gets You almost there (comments mention the Bin folder issue):
https://conficient.wordpress.com/2013/11/27/asp-net-razor-views-in-class-libraries/
Another Guide with Bin included:
http://thetoeb.de/2014/01/05/enabling-mvc5-intellisense-in-a-classlibrary-project/
But the only point to any of that is if you're avoiding having a real ASP.Net MVC site. So, now you'll need something to run it... and there are options, but that's beyond this entry.
Almost There
If you just want your views to be compiled, and re-used as a project by many other real ASP.Net MVC projects, then instead you could just Use Razor Generator , but even still here, you might not want to create your project as a Class library, because such just isn't fun...
Install VS Extension for Razor Generator
Add new Class Library Project
Add NuGet package to your library for RazorGenerator.Mvc
Add NuGet package to your library for PrecompiledMvcViewEngineContrib
Create a Views folder and a controller named folder under that in your library for the virual path you want these accessed as
Move any views to that new \Views\ControllerName\ folder
Set all these library views to Custom Tool RazorGenerator (right-click properties on view)
Add reference to your library from your real ASP.Net MVC web application
From there I often have problem still. I'll be stuck in C# 2.0 unless I add Microsoft.CodeDom.Providers.DotNetCompilerPlatform nuget package. Which is for 4.5, so for 4.6.x one could modify the new codedom section in app.config to
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">
<providerOption name="CompilerVersion" value="v4.0"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
Now you can use "var" as an implict type and other modern C# features.
Next I had an issue with System.Linq extension methods not being found despite having referenced it... and life just isn't quite right... if you want it all... But that is a start if that's a path you want to walk further down.
Simplest Option
But if you take the Advice of the Razor Generator crew, and actually install Razor Generator on top of a regular MVC Web Application (just create your "library" as one), then almost none of this work is necessary...
Have a Main real MVC ASP.Net site
Create a new MVC ASP.Net site to act as your "library", so you don't have to mess with things as much
Install Nuget Package for RazorGenerator.MVC to "library"
Install Nuget Package for PrecompiledMvcViewEngineContrib to "library"
Move views to similiar structure in library and mark as Custom Tool RazorGenerator
Reference your "library" from main site, and it'll all work with less hassle this way.
The beauty is that your referenced "library" has App Start code that will run at app start of your main app, and that will register the PreCompiledViewEngine, which knows about virual paths, and not just physical paths. Then your RazorGenerator Custom Tool views will define their virtual path, and when the view path is resolved, it can find them.
Nice Reference on the topic:
https://www.c-sharpcorner.com/UploadFile/97fc7a/article-precompiled-razor-view-using-razorgenerator-mvc-and/
Your project must be a Web Application for intellisense to work properly. Web Application is just a special class library.

How to keep clean ASP.NET web.config file for a new MVC3/Azure project using only <system.webServer>?

I just created a new project in MVC3 using EF4 code first deployed on Windows Azure.
I want to keep my "web.config" file as clean as possible because it's a little complicated to understand all tags it contains.
I notice two sections: <system.web> and <system.webServer>
The first is for IIS6 and the second for IIS7+
I do not need backward compatibility so want to delete the first.
I converted a good part of the first into the second, but I cannot find how to convert these sections:
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral />
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral />
<add assembly="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral />
</assemblies>
</compilation>
<pages validateRequest="false">
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
How to do this so that I can delete the deprecated <system.web>?
Not all of the elements are deprecated. The two most important sections are /system.web/httpHandlers which has moved to /system.webServer/handlers and /system.web/httpModules which is now /system.webServer/modules. You shouldn't need to touch the above configuration any further as the elements within are still part of the system.web element even in IIS7. Have you tried running your site after your changes?

Resources