|
yes why not.. Let me see your code.
Is it happening when you are connecting to a computer in LAN.. Is the domain configured correctly.. ?
Can you connect the remote machine in lan manually?
|
|
|
|
|
I am trying impersonation in remoting ..
The program runs fine when i turn off impersonation. I am running client and server both on the same machine(VISTA).
I have created the user account on the machine .. and it runs fine when i use secure channel and turn impersonation off..
I have also checked that when impersonation is off and using secure channel .. it allows only the users that i have created to logon .. otherwise it gives authentication failure.
Following is the code :
Server:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
using System.Threading;
using System.Security.Principal;
namespace ns_application
{
namespace ns_server
{
public class cls_server
{
static void Main(string[] args)
{
//TcpChannel channel = new TcpChannel(8080);
IDictionary props = (IDictionary) new Hashtable();
IPrincipal threadPrincipal;
props.Add("port", "8080");
props.Add("secure", "true");
props.Add("impersonate", "true");
props.Add("protectionLevel", "EncryptAndSign");
//props.Add("username", "Vishwjeet");
//props.Add("password", "pwd");
//props.Add("authorizationModule", "AuthorizeUser");
//BinaryClientFormatterSinkProvider cp = new BinaryClientFormatterSinkProvider();
//BinaryServerFormatterSinkProvider sp = new BinaryServerFormatterSinkProvider();
IChannel chan = new TcpChannel(props,null,null);
ChannelServices.RegisterChannel(chan,true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ns_registeruser.cls_registeruser), "ApplicationMain", WellKnownObjectMode.Singleton);
threadPrincipal = Thread.CurrentPrincipal;
Console.WriteLine(threadPrincipal.Identity.Name);
Console.WriteLine(threadPrincipal.Identity.IsAuthenticated);
Console.WriteLine(threadPrincipal.Identity.AuthenticationType); Console.WriteLine("Server Started .. ");
Console.ReadLine();
}
}
}
}
Methods :
using System;
using System.Runtime.Serialization;
using System.Reflection;
using System.Data;
using System.Threading;
using System.Security.Principal;
namespace ns_application
{
namespace ns_registeruser
{
//[Serializable]
public class cls_whereitruns:MarshalByRefObject
{
private int _IDNo;
public int IDNo
{
get
{
return _IDNo;
}
set
{
_IDNo = value;
}
}
public int FutureofID()
{
IDNo = IDNo * 5;
Console.WriteLine("Calculated future of ID : {0} :::: {1} :::: {2}", IDNo,this.ToString(),AppDomain.CurrentDomain.FriendlyName);
return(IDNo);
}
public cls_whereitruns(int IDNo)
{
this.IDNo = IDNo;
Console.WriteLine("Created ID : {0} :::: {1} :::: {2}", IDNo, this.ToString(), AppDomain.CurrentDomain.FriendlyName);
}
public DataTable RMS_DIV_Data()
{
//OleDbDataAdapter dataAdapter = new TempDataSet.
TempDataSetTableAdapters.DIV60 da = new ns_application.TempDataSetTableAdapters.DIV60();
TempDataSet.__TKOCLIENT_DIV160DataTable internalTable = new TempDataSet.__TKOCLIENT_DIV160DataTable();
da.Fill(internalTable);
Console.WriteLine("Methods Connection String :: " + System.Configuration.ConfigurationManager.ConnectionStrings["ns_application.Properties.Settings.RetentionManagementSystemConnectionString"]);
Console.WriteLine(internalTable[0][0]);
return internalTable;
}
}
//public class cls_registeruser
public class cls_registeruser : MarshalByRefObject
{
public cls_whereitruns _obj = new cls_whereitruns(5);
private string _username;
public string username
{
get { return _username; }
}
public cls_registeruser()
{
_username = "Blank";
IPrincipal threadPrincipal = Thread.CurrentPrincipal;
Console.WriteLine(threadPrincipal.Identity.Name);
Console.WriteLine(threadPrincipal.Identity.IsAuthenticated);
Console.WriteLine(threadPrincipal.Identity.AuthenticationType);
Console.WriteLine("Registered User " + username);
}
public cls_registeruser(string username)
{
_username = username;
Console.WriteLine("Registered User " + username);
}
~cls_registeruser()
{
Console.WriteLine("Destructor called");
}
}
}
}
Client:
#define VISTA
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
namespace ns_application
{
namespace ns_client
{
public class cls_client
{
static void Main(string[] args)
{
IChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel,true);
//try
//{
#if VISTA
ns_registeruser.cls_registeruser user_obj = (ns_registeruser.cls_registeruser)Activator.GetObject(typeof(ns_registeruser.cls_registeruser), "tcp://kk-pc:8080/ApplicationMain");
#else
ns_registeruser.cls_registeruser user_obj = (ns_registeruser.cls_registeruser)Activator.GetObject(typeof(ns_registeruser.cls_registeruser), "tcp://everest:8080/ApplicationMain");
#endif
IDictionary props = ChannelServices.GetChannelSinkProperties(user_obj);
//props["domain"] = "WORKGROUP11";
#if VISTA
props["tokenImpersonationLevel"] = "identification";
props["username"] = "Vishwjeet";
props["password"] = "pwd";
props["secure"] = "true";
props["protectionLevel"] = "EncryptAndSign";
Console.WriteLine(props["username"]);
#else
props["username"] = "something";
Console.WriteLine(props["username"]);
props["password"] = "hello";
#endif
Console.WriteLine("Till 1");
Console.WriteLine(user_obj._obj.FutureofID());
Console.WriteLine("Till 2");
Console.WriteLine(user_obj._obj.FutureofID());
user_obj._obj.IDNo = 35;
//Console.WriteLine("Client Connection String :: " + System.Configuration.ConfigurationManager.ConnectionStrings["ns_application.Properties.Settings.RetentionManagementSystemConnectionString"]);
Console.WriteLine(user_obj._obj.FutureofID());
Console.WriteLine(user_obj._obj.IDNo);
//Console.WriteLine(user_obj._obj.RMS_DIV_Data());
Console.WriteLine("Client Object Created for user . ." + user_obj.username);
//}
//catch (Exception e)
//{
// Console.WriteLine(e.ToString());
//}
Console.ReadLine();
}
}
}
}
|
|
|
|
|
I have login page and a main page in the asp.net application.In web.config, session Timeout value is set as 5 mins.
My requirements are as below
1.If the main page is idle for 5 mins, the session will expire and the same page will be retained. If the user tries to do some action then it has to redirect to loginpage.
bebuggiung steps
1.comes to session end event in global.asax and the retain the main page
2.comes to session start event in global.asax after the user tries to do some action.
3.check the condition and redirects to login page
2.If the session ends at the time of some action is going in the main page(eg executing a stored procedure for a long time ) then the session has to continue upto the action gets finished.Once it is completed session timeout value has to reset as original value (5 mins)
bebuggiung steps
1. Comes to session end event and assigns the session timeout value to retain the running process in the main page.
I have used the following code to do the above requirements.It is working fine in IIS V5.1 and not working in IIs 6.0 in win 2003 server
Web.config
sessionState timeout="5" mode ="InProc" cookieless ="false"
Global.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["Button"] = "Started";
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
HttpContext context = HttpContext.Current;
HttpCookieCollection cookies = context.Request.Cookies;
if (cookies["starttime"] == null)
{
HttpCookie cookie = new HttpCookie("starttime", DateTime.Now.ToString());
cookie.Path = "/";
context.Response.Cookies.Add(cookie);
cookie.HttpOnly = true;
Application["Button"] = "Started";
}
else
{
if (Application["Button"] == "NotClicked" || Application["Button"] == "Error")
{
context.Response.Redirect("~/Logon.aspx");
}
}
}
void Session_End(object sender, EventArgs e)
{
if (Application["Button"] == "Clicked")
{
Session.Timeout = 60;
}
else
{
Application["Button"] = "NotClicked";
}
}
}
Main Page Load
Application["Button"] = "NotClicked";
Main Page Button Click (calling sp in this button)
Application["Button"] = "Clicked";
Please any one help me out to do the same in IIS 6.0. I have tried with worker process idle time also in application pool.
What is the difference in IIS 6.0 with IIS 5.1 using the above code with cookies? Please any one reply me as soon as possible. its very urgent....
Prasanna
|
|
|
|
|
I need to know the user IP to give the right limit to access my website,
how to detect the user IP?
and moreover, how to know which country is the user from?
thanks!
|
|
|
|
|
|
This is a good article.
|
|
|
|
|
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
I saw from internet, there are also others have the same problem. then some people suggest using the following code:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
but it shows the result as follows:
fe70::8c3:258f:3f47:fd6b%12
this is IP??
do you have more comments on this?
thank you again!!
|
|
|
|
|
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
Hi you are in right direction and it is correct. It alwasy gives IP: 127.0.0.1 because you are requesting from your local machine.
When you will acces you web application via different machine then it will give the correct IP.
Anyway your code is correct.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
thanks, I see,
but do you know
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
gives also IP? or sth else?
thank you again!!
your article is great!!
|
|
|
|
|
This will give Host IP where your application is deployed. But you are looking for visitor/Client IP.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
really? if so, I am confused by this code.
thanks again!
|
|
|
|
|
Yes
Now your next job is to find the country name.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
Seraph_summer wrote: your article is great!!
At least the Database provided in the article is the most important part of it. Its a great one indeed.
|
|
|
|
|
Client IP could be found from
ip=Request.ServerVariables("HTTP_X_FORWARDED_FOR");
if(ip==string.Empty)
{
ip=Request.ServerVariables("REMOTE_ADDR");
}
|
|
|
|
|
Hi, thanks!
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
I saw from internet, there are also others have the same problem. then some people suggest using the following code:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
but it shows the result as follows:
fe70::8c3:258f:3f47:fd6b%12
this is IP??
do you have more comments on this?
thank you again!!
|
|
|
|
|
|
|
If the user is behind a proxy then REMOTE_ADDR will be the proxy IP address and HTTP_X_FORWARDED_FOR will be the client IP address. HTTP_X_FORWARDED_FOR can consist of multiple comma separated IP addresses for each proxy the request passes through. Generally, client IP is the first of them.
Finally, you can rely on the above methods only for Transparent proxies. There is no way to trace the actual IP in case of Anonymous or Distorting proxies.
One more good tool for finding country from an IP is this one[^] on codeplex.
|
|
|
|
|
Please Help ,I have 3 day for my presentation in university just
I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
I use VS2008(C#) without service pack.PLZ Hlp
|
|
|
|
|
morteza451 wrote: I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
Can you please give us the code block ?
If you want to know more about these controls, please read this
ASP.NET Login Controls Overview[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello everyone,
I am using Windows Server 2003 + VSTS 2008 + .Net 3.5 + C# + ASP.Net + IIS 6.0. I host some files (wmv video file and html file) on the web server, I want to know whether there are any easy to use authentication approach to let user input username and password before they can access (I want to prevent anonymous access)? Since the web site has also aspx ASP.Net page, and I want to use an unified authentication solution for wmv, html and aspx page. If prefer any solution which utilizes username and password stored in SQL Server database which my application already has/use.
Any ideas?
thanks in advance,
George
|
|
|
|
|
Hey George,
I am seeing ur question after a long time. How are u doing ?
George_George wrote: If prefer any solution which utilizes username and password stored in SQL Server database which my application already has/use.
So what is the problem with that ? why you are not authenticate the user from SQL Server itself . maintin session for giving the proper access of the page. or you can implement Roles for that !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I am fine, thank! Any ideas to my question?
|
|
|
|
|
in my asp page i have a text box and i want add a text and newline and text again repeatedly.
i uase txt1.text +="hello"+Environment.NewLine ;
but the newline is not working. any idea why ?
|
|
|
|
|
Because you've not set the control to be multiline. It's a property on the control.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|