function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sravan36sravan36 

Customer Portal Single Sign On using Web Service call.

Hi all,

    I am trying to login into SFDC cutomer portal view cases page  from other platform i.e .Net. I have generated an enterprise WSDL and incorporated into .Net web application, then i wrote the following code which login and redirects me to the customer portal login page. but in this, i am getting an error as below and it is not taking me to the requested page (ViewCases).

Error: File Not Found.
Authorization Required
 

You must first log in or register before accessing this page. 
If you have forgotten your password, click Forgot Password to reset it. 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SFDCApplication.sforce;
using System.Web.Services.Protocols;
namespace SFDCApplication
{
public partial class _Default : System.Web.UI.Page
{
private SforceService newService;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lnkLink_Click(object sender, EventArgs e)
{
try
{

string userName = "*********@******";
string passWord = "**********";

newService = new SforceService();
string orgId = "**************";
string portId = "****************";
LoginScopeHeader header = new LoginScopeHeader();
header.organizationId = orgId;
header.portalId = portId;
newService.LoginScopeHeaderValue = header;
LoginResult logRes = new LoginResult();
try
{
logRes = newService.login(userName, passWord);
}
catch (SoapException ex)
{
Console.WriteLine(ex.Code);
Console.WriteLine("An unexpected error has occurred: " + ex.Message);
Console.WriteLine(ex.StackTrace);
throw new Exception();
}
if (logRes.passwordExpired)
{
Console.WriteLine("An error has occurred. Your password has expired.");
throw new Exception();
}
string oldAuthEndPointURL = newService.Url;
newService.Url = logRes.serverUrl;
newService.SessionHeaderValue = new SessionHeader();
newService.SessionHeaderValue.sessionId = logRes.sessionId;
 
if (logRes.sessionId != "" && logRes.sessionId != string.Empty)
{
string redirectURL = "https://<CompanyName>.testing.cs10.force.com/customerportal /apex/viewcases?sessionid=" + logRes.sessionId;
Response.Redirect(redirectURL);
}
}
catch (Exception ex)
{
lblErr.Text = ex.Message;
}
}
}
}


Also i am getting the same session id again and again instead of different session id's each and every time. Then i just changed my code a little bit.
Instead of redirecting i called the logout() method, which flushes the existing session and again i called the Login() method, which creates a new session id for me. Code change as below

if (logRes.sessionId != "" && logRes.sessionId != string.Empty)
{
       this.newService.logout();
       logRes = newService.login(userName, passWord);
       string redirectURL = "https://<CompanyName>.testing.cs10.force.com/customerportal /apex/viewcases?sessionid=" + logRes.sessionId;
       Response.Redirect(redirectURL);
}

- luckily it worked and i was getting a new session id each and every time. 

After this also i am getting the same error as

Error: File Not Found.
Authorization Required
 

You must first log in or register before accessing this page. 
If you have forgotten your password, click Forgot Password to reset it. 


What is wrong in this, am i missing out anything in code. Any suggestions and ideas will be appreciated.

Thanks in advance.