Getting broken images on localhost but not on websites - c#

On our website we have images dropped on a grid with the following line:
imgUpdated.ImageUrl = "./images/Test_Icon.gif";
This works fine when published to production or test websites but within the IDE it gives broken (Red-X) images. Properties on the broken image says this:
http://localhost:52168/OurApp/images/Test_Icon.gif
If I attempt to past that into a browser, it redirects me to the login page with the following URL:
http://localhost:52168/OurApp/login.aspx?ReturnUrl=%2fITRequest%2fimages%2fTest_Icon.gif
I'd appreciate any help you might offer. I've already tried setting up a virtual directory in IIS and taking out the period but that didn't help.

create a web.config file with the following xml and place it in your images folder
<configuration>
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</configuration>
This is likely the reason your IDE doesn't show the images. If your browser is giving a 401 response and redirecting to your login page, the IDE is expecting an image MINE type.
You can find more information on the authorization section

Your image or any other content paths should start with forward slash / which points always to the root of your website. That way no matter in what environment you are your path will always be the same. So, answering your question... your path should look like this:
imgUpdated.ImageUrl = "/images/Test_Icon.gif";

Related

#gets appended at the end of url on clicking rad tab

I have uploaded my application to live server published code into iis my tab doesn't works on live,tab gets post back on the local, # gets appended automatically at the end of the url unable to postback on the server which causes the postback working to stop.
Look for JavaScript errors on your page. If there are, the tab will not be able to execute its JS logic, so it will act as an ordinary anchor and add the hash to the URL.
It is often the case that webresources do not load on your production server because of permissions. Check these two articles for more info on troubleshooting that:
http://www.telerik.com/help/aspnet-ajax/introduction-troubleshooting.html
http://www.telerik.com/help/aspnet-ajax/introduction-web-resources-troubleshooting.html
You will, most likely, need to let your user access webresource:
<location path="Telerik.Web.UI.WebResource.axd">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Also, you can try using the CDN to avoid loading resources from your server: http://www.telerik.com/help/aspnet-ajax/scriptmanager-cdn-support.html. If you have it enabled already, then you may not have connection to the cloud where the scrips come from, so you can consider disabling it.

Url Rewriting ASP.NET - Some images refuse to load

I have recently implemented UrlRewriter (http://urlrewriter.net) on my website and am having some issues.
I am implementing it so the page requests are extension-less. For example, www.example.com/my-cool-product, redirects to www.example.com/Product.aspx?id=1. This works fine.
The problem I am having is that, some of my site images are refusing to be served as static content. If I put the path to some of images on my site, they are served up right away (as static content), but some images try to route through the .NET pipeline.
For example, www.example.com/Asset/Image/Image.png returns a 404 as it is trying to hit up www.example.com/Asset/Image/Default.aspx.
Can anyone shed any light on why this is happening for some images and not for others?
What version of IIS are you using? You may need:
<modules runAllManagedModulesForAllRequests="true">
In your web.config <system.webServer> block
Or set a <base> url in your page head

The same REST service, different behavior for different virtual directories. 404 error

1- I have a piece of code that is deployed on the server. This code calls for a REST service.
2- The same physical server, where the code is, is being pointed at by multiple virtual directories, each virtual folder has a different name.
3- For the first virtual directory, everything is working fine and the code calls the REST service.
4- For the second virtual directory, which points to the same exact code, and points to the same physical folder (not even a copy of the code) can't find the REST service, it gives 404.
Any idea what could be happening? I am not sure if this is enough information or not, I would be glad to provide more.
The URL is constructed dynamically this way
RouteTable.Routes.Add(new ServiceRoute("rest/AuthenticationAttempt", new WebServiceHostFactory(), typeof(AuthenticationService)));
In the web.config, I have this
<location path="rest">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
The service URL is
http://10.30.10.172/OnlineServicing/rest/AuthenticationAttempt/
OnlineServicing is the virtual directory name, AuthenticationAttempt is the service name. However, the deployed code doesn't have a rest folder, it looks like the code handles this.

Response.WriteFile from other aspx file

I have a Login.aspx page, and I wanna incude some piece of code in that page. I know I can do Response.WriteFile ("HelloMessage.aspx"), but if I simply do Project->New Item->Web Page, the GelloMessage.aspx page will be accesible throught Web browser. I wanna do this HelloMessage.aspx file unaccessible.
How to do this?
And question 2, can I keep aspx files in my custom folders?
Yes, you can keep apsx files in subfolders. Those folders become part of the URL (as long as you don't add routing).
And you can block files using the <authorize> tag in web.config. Which could solve your fist problem (but to who would you allow access to Hello.aspx ?)
Every folder can has its own web.config. So, an easy example:
For all pages in the same folder as this config, deny access to anonymous users and allow access to all logged-in users:
<authorization>
<deny users="?" />
<allow users = "*" />
</authorization>
If you have some markup that you'd like to include in several pages, then you should either use a user control, or perhaps a master page.

Disable Caching For A Single JS File Using Web.config

I currently cache everything possible on my site (images, JS, CSS). There is only one JS file that I need to be loaded fresh every single time. How do I omit just one file from caching, using web.config, whilst leaving everything else cached?
Note that I tried another link here, and it didn't seem to stop the caching of my file:
How do I disable caching of an individual file in IIS 7 using weserver config settings
How about:
<configuration>
<location path="path/to/the/file.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
(Note that the path is relative to the web.config file)
I don't think you can do it using web.config, but you could add a unique querystring parameter to the javascript url in order for it to be loaded every time:
If you are using ASP.NET
<script src="mycode.js?<%=System.Guid.NewGuid.ToString()%>"></script>
Set the path for it not as a static URL but get an ASPX page to serve the script. Inside your ASPX page just send back the text:
byte[] javascriptTextBuffer = GetMyJavascript();
Response.ContentType = "text/javascript";
Response.Write(javascriptTextBuffer);
Inside the page turn off caching.
Having said that, it seems to me that you are doing something wrong that have to load the JavaScript file everytime. Make scripts static but use parameters to drive versatility.

Categories

Resources