I'm using Uploadify Plugin in my webform and get a error Http 302. I dont know how this happen and how to fix it, anybody help me fix it. thank in advance.
Here is my javascript code :
<link href="jscript/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script src="jscript/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="jscript/uploadify/swfobject.js" type="text/javascript"></script>
<script src="jscript/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#custom_file_upload').uploadify({
'uploader': 'jscript/uploadify/uploadify.swf',
'script': 'admin_ServicesPhotosManager.aspx',
'cancelImg': 'jscript/uploadify/cancel.png',
'folder': 'Images/Uploads',
'fileExt': '*.jpg;*.gif;*.png',
'fileDesc': 'Image Files (.JPG, .GIF, .PNG)',
'multi': true,
'queueSizeLimit': 5,
'queueID': 'custom-queue',
'onSelectOnce': function (event, data) {
$('#status-message').text(data.filesSelected + ' files have been added to the queue.');
},
'onAllComplete': function (event, data) {
alert(data.filesUploaded + ' files uploaded successfully !');
window.location = 'admin_ServicesPhotosManager.aspx';
},
'onError': function (event, ID, fileObj, errorObj) {
alert(errorObj.type + ' Error: ' + errorObj.info + " file : " + fileObj.type);
}
});
});
</script>
and my admin_servicephotosmanager.aspx code :
<div id="status-message">
</div>
<div id="custom-queue">
</div>
<input type="file" id="custom_file_upload" name="file_upload" />
<a href="javascript:$('#custom_file_upload').uploadifyUpload();" class="file-upload">
</a>
finally is my admin_servicephotosmanager.aspx.cs code behind :
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Files["Filedata"] != null)
{
HttpPostedFile uploads = Request.Files["Filedata"];
MessageBox.Instance.DisplayMessageAndRefresh(uploads.ContentLength.ToString(), false);
}
}
Update my web.config :
<location path="~/admin_ServicesPhotosManager.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
<httpRuntime executionTimeout="1800"
maxRequestLength="1048576"
useFullyQualifiedRedirectUrl="false"/>
</system.web>
<system.web>
<httpRuntime
executionTimeout="110"
maxRequestLength="102400"
requestLengthDiskThreshold="80"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="5000"
enableKernelOutputCache="true"
enableVersionHeader="true"
requireRootedSaveAsPath="true"
enable="true"
shutdownTimeout="90"
delayNotificationTimeout="5"
waitChangeNotification="0"
maxWaitChangeNotification="0"
enableHeaderChecking="true"
sendCacheControlHeader="true"
apartmentThreading="false" /></system.web>
somebody help me fix http 302 error . thanks in advance.
The request probably was blocked, check if you have security issue.
Remove
<authorization>
<allow users="*"/>
</authorization>
From your web.config, it will work.
Related
here is my Login master page code, Few Js file and css file I cannot use CDN an d while loading the login page is throw error stating : '$'is undefined
<link rel="stylesheet" href="Assets/css/style.css" type="text/css" />
<script src="../Assets/lib/jquery/jquery.min.js" type="text/javascript"></script>
<script src="../Assets/lib/perfect-scrollbar/js/perfect-scrollbar.jquery.min.js" type="text/javascript"></script>
<script src="../Assets/js/main.js" type="text/javascript"></script>
<script src="../Assets/lib/bootstrap/dist/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../Assets/js/Portal.js" type="text/javascript"></script>
<script src="../Assets/js/BootstrapValidator.js"></script>
<script>
$(document).ready(function () {
//initialize the javascript
App.init();
});
</script>
My Path to the files is Project/Assets folder
Things I have tried :
<location path="js">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
In the request filtering added file extension .js and .css and Allowed to True.Kindly help
When I go to the root of my ASP.NET website, the request goes into the ASP.NET pipeline and then returns index.html.
Is there a way in web.config to configure this so that IIS simply returns the file without going into the ASP.NET pipeline?
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<h1>Test</h1>
</body>
</html>
Global.asax:
using System.Web;
namespace Test
{
public class Global : HttpApplication
{
protected void Application_BeginRequest()
{
var url = this.Request.Url;
}
}
}
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
You can set runAllManagedModulesForAllRequests=false inside web.config. It has other side effects, but can give a try first.
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
</system.webServer>
I have used the credential tag in web.config file to authenticate my admin. now I want to know is there any way to make a page with a form for admin to change his username and password?
this is my code in web.config:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<sessionState cookieless="AutoDetect" mode="InProc" timeout="114400">
</sessionState>
<authentication mode="Forms">
<forms timeout="1440" loginUrl="~/entrance_before_paying.aspx" defaultUrl="Admin/Default.aspx" name=".ASPXFORMSDEMO" cookieless="AutoDetect" protection="All">
<credentials passwordFormat="Clear">
<user name="elmiragolshanff#yahoo.com" password="elmira" />
</credentials>
</forms>
</authentication>
</system.web>
I used this code in my sign in page to check if the user is admin or not:
private void enter()
{
if (FormsAuthentication.Authenticate(TextBox1.Text.Trim(), TextBox2.Text.Trim()))
{
FormsAuthentication.RedirectFromLoginPage("admin user name in credential tag", true);
}
else
{
// enter as a user}
}
}
yes, you can do it this way
<location path="Admin">
<system.web>
<authorization>
<allow users="ram"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
Use above code in web.config file. this will allow only user 'ram' to access inside 'Admin' folder.
I used this code now it works fine
<form ID="form1" runat="server">
<div>
<asp:TextBox ID="txtUsername" runat="server">
</asp:TextBox>
<asp:TextBox ID="txtPassword" runat="server">
</asp:TextBox>
<asp:Button ID="btnWrite" runat="server" onclick="btnWrite_Click" Text="Modify" />
</div>
in ChangePassword.aspx.cs:
protected void btnWrite_Click(object sender, EventArgs e)
{
Configuration webconfig = WebConfigurationManager.OpenWebConfiguration("/wite your site name");
SystemWebSectionGroup sysweb = (SystemWebSectionGroup)webconfig.GetSectionGroup("system.web");
AuthenticationSection authSection = sysweb.Authentication;
FormsAuthenticationUserCollection users = authSection.Forms.Credentials.Users;
FormsAuthenticationUser user = users[0];
user.Name = txtUsername.Text;
user.Password = txtPassword.Text;
webconfig.Save();
}
I am tring to utilize a simple SignalR sample and from a reason I get the 404 code from the following -
<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
I checked the SignalR documentation and changed my web.config according to what is suggests there still I get that 404 status code.
my code follows -
Web.Config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<httpRuntime/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
</configuration>
Default.aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-0.5.3.min.js" type="text/javascript"></script>
<script src="<%= ResolveUrl("~/signalr/hubs") %>" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//var connection = new Connection( "127.0.0.1");
// Proxy created on the fly
var chat = $.connection.chatt;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
$("#broadcast").click(function () {
// Call the chat method on the server
chat.send($('#msg').val());
});
// Start the connection
$.connection.hub.start();
});
</script>
</head>
<input type="text" id="msg" />
<input type="button" id="broadcast" value="broadcast" />
<ul id="messages">
</ul>
</html>
Please assist.
I had this same problem, the solution is putting this in your Global.asax file:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs();
}
Unfortunately this isn't documented anywhere, even though it's an essential part of SignalR configuration...
in web.config code is
section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<forms loginUrl="Login.aspx" cookieless="UseCookies">
</forms>
</authentication>
whenever iam closing application and logging back user remains in and ask me to log out.. i want to make sure whenever application starts it should not be logged in previously..
this is web.config code..
<authentication mode="Forms">
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<forms loginUrl="Login.aspx" cookieless="UseCookies">
</forms>
</authentication>
<authorization>
<allow roles="Administrator,Attorney,Director of Operations,Office Manager,Paralegal,Partner,Processor,Salary Admin,Unit Manager"/>
<deny users="?"/>
</authorization>
<pages>
</pages>
</system.web>
Login button code
string [] arr = new string[10];
bool bCheckUser;
try
{
if ((txtUserName.Text == "") || (txtPassword.Text == ""))
{
lblError.Visible = true;
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = "Enter UserName and Password";
}
else
{
bCheckUser = Membership.ValidateUser(txtUserName.Text, txtPassword.Text);
arr = Roles.GetRolesForUser(txtUserName.Text);
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
FormsAuthentication.Authenticate(txtUserName.Text, txtPassword.Text);
if (bCheckUser == true)
{
lblError.Visible = false;
Response.Redirect("MainMenu.aspx");
}
else
{
lblError.Visible = true;
lblError.ForeColor = System.Drawing.Color.Red;
lblError.Text = "You Username or Password is Invalid. Please try Again";
}
}
}
catch(Exception ex)
{
lblError.Text = ex.Message.ToString();
}
}
You are passing true to this method that is to create persistent cookies:
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
pass false instead and also move that inside of if block and remove that redirect if you don't want hard redirect:
if (bCheckUser == true)
{
lblError.Visible = false;
// Response.Redirect("MainMenu.aspx");
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
}
Or use SetAuthCookie method like below:
if (bCheckUser == true)
{
lblError.Visible = false;
FormsAuthentication.SetAuthCookie(txtUserName.Text, false);
Response.Redirect("MainMenu.aspx");
}
Edit:
It looks like you are calling FormsAuthentication.RedirectFromLoginPage regardless of whether Membership.ValidateUser returns true or false. That might have something to do with it. Is this code being called in the Page_Load of your login page?
A couple of questions I have for you:
Are you actually closing the browser
and then reopening it, or just
returning to your site after
receiving an error in the same
browser?
Does your login page have a Remember
Me setting?
Have you restricted access to your
webpages in your webconfig?
By default I think the webconfig leaves most pages open. You'll need an authorization section to restrict access.
<authorization>
<deny users="?" />
</authorization>
Here's some links to check out as well:
http://ondotnet.com/pub/a/dotnet/2004/02/02/effectiveformsauth.html
http://www.asp.net/security/tutorials/an-overview-of-forms-authentication-vb